package com.zd01.servers;

import com.zd01.anno.LogOperation;
import com.zd01.interfaces.ReportInterface;
import com.zd01.mapper.StudentMapper;
import com.zd01.model.ReportSexModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class ReportServer implements ReportInterface {
    @Autowired
    private StudentMapper studentMapper;

    @Override
    public ReportSexModel getSexCount() {
        List<Map<String, Object>> list = studentMapper.getSexCount();//[{ssex:男, num:1},{ssex:女, num:2}]
        List<Object> sex = list.stream().map(mapVal -> mapVal.get("ssex")).collect(Collectors.toList());
        List<Object> sexCount = list.stream().map(mapVal -> mapVal.get("num")).collect(Collectors.toList());
        return new ReportSexModel(sex, sexCount);
    }

    @Override
    public List<Map<String, Object>> getSexCount2() {
        List<Map<String, Object>> list = studentMapper.getSexCount2();//[{ssex:男, num:1},{ssex:女, num:2}]

        return list;
    }

}
